import 'package:oramemo/core/config/api_config.dart';
import 'package:oramemo/core/models/api_response.dart';
import 'package:oramemo/core/network/dio_client.dart';
import 'package:oramemo/entity/sendcode_entity.dart';
import 'package:oramemo/entity/getinfo_entity.dart';


class AuthRepository {
  final DioClient _client = DioClient();

  Future<ApiResponse<Map<String, dynamic>>> login({
    required String username,
    String? password,
    String? code,
    String? uuid,
    String loginType = '1',
  }) async {
    final response = await _client.request(
      path: ApiConfig.login,
      method: 'POST',
      data: {
        'username': username,
        'password': password,
        'code': code,
        'uuid': uuid,
        'userType': '1',
        'loginType': loginType,
      },
    );
    return ApiResponse.fromJson(
        response.data, (data) => data as Map<String, dynamic>);
  }

  Future<ApiResponse<SendcodeEntity>> sendEmail(String email) async {
    final response = await _client.request(
      path: ApiConfig.sendEmail,
      method: 'GET',
      queryParameters: {'receiveAccount': email, 'userType': '1'},
    );
    return ApiResponse.fromJson(response.data, (data) => SendcodeEntity.fromJson(data));
  }

  Future<ApiResponse<void>> logout() async {
    final response = await _client.request(
      path: ApiConfig.logout,
      method: 'POST',
    );
    return ApiResponse.fromJson(response.data, null);
  }

  Future<ApiResponse<GetinfoEntity>> getInfo() async {
    final response = await _client.request(
      path: ApiConfig.getInfo,
      method: 'GET',
    );
    return ApiResponse.fromJson(
        response.data, (data) => GetinfoEntity.fromJson(data));
  }
}
